public class T4_0906_0514 {
    public static Object lock1 = new Object();
    public static Object lock2 = new Object();

    public static void main(String[] args) {

        Thread thread1 = new Thread("thread1") {
            @Override
            public void run() {
                synchronized (lock1) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    synchronized (lock2) {
                        System.out.println(Thread.currentThread().getName() + "结束");
                    }

                }
            }
        };

        Thread thread2 = new Thread(() -> {
            synchronized (lock2) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (lock1) {
                    System.out.println(Thread.currentThread().getName() + "结束");
                }
            }
        }, "thread2");

        thread1.start();
        thread2.start();
    }
}
